package lift;

public class PersonThread extends Thread{
	private int startFloor;
	private int endFloor;
	private int startTime;
	private LiftMonitor monitor;
	
	public PersonThread(LiftMonitor monitor){
		this.monitor = monitor;
		startFloor = ((int)(Math.random()*7.0));
		endFloor = startFloor;
		while(endFloor == startFloor){
			endFloor = ((int)(Math.random()*7.0));
		}
		//System.out.println("person: " + startFloor + " " + endFloor);
		startTime = 1000*((int)(Math.random()*46.0)); // sleep need milliseconds
	}
	
	public void run(){
		try {
			//while(true){
			startTime = 1000*((int)(Math.random()*46.0)); // sleep need milliseconds
			//startTime = 1000;
			Thread.sleep(((long)startTime));
			
			monitor.addPersonWaiting(startFloor);
			
			monitor.boardLift(startFloor, endFloor);
			
			monitor.unBoardLift(endFloor);
			

			//}
		} catch (Exception e) {
			// TODO: handle exception
		}
	}

}
